﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class equipmentShow : MonoBehaviour
{
    public int id;//装备id号
    public int index;//弹框序号
    public Image showImage;
    public Text showName;
    public Text showNum;
    public Text add;
    public Image btnImage;
    public bool canLoad ;

    string[] imagesPath = { "RoleAttribute/衣服", "RoleAttribute/头盔", "RoleAttribute/项链", "RoleAttribute/戒指", "RoleAttribute/武器", "RoleAttribute/护手" };//卸下之后的图片的路径
    MainItem mainItem;
    GameObject[] parentObject;
    private void Start()
    {
        mainItem = RoleAttributeManager._instance.mainItem;
        //item = RoleAttributeManager._instance.item;
        parentObject = RoleAttributeManager._instance.parentObject;
    }
    public void ClickEquipOne()
    {
        
        //卸下
        if (canLoad)
        {
            btnImage.sprite = Resources.Load<Sprite>("RoleAttribute/装备");
            parentObject[index].GetComponent<Image>().sprite = Resources.Load<Sprite>(imagesPath[index]);
            parentObject[index].transform.GetChild(0).gameObject.SetActive(false);
            VariableDocument.GetInstance.equiped[index] = -1;
            canLoad = false;
        }
        //装备
        else
        {
            btnImage.sprite = Resources.Load<Sprite>("RoleAttribute/卸下");
            parentObject[index].GetComponent<Image>().sprite = showImage.sprite;
            parentObject[index].transform.GetChild(0).gameObject.SetActive(true);
            VariableDocument.GetInstance.equiped[index] = id;
            canLoad = true;
        }

        //Debug.Log(VariableDocument.GetInstance.equiped[0] + " " + VariableDocument.GetInstance.equiped[1] + " " + VariableDocument.GetInstance.equiped[2] + " " + VariableDocument.GetInstance.equiped[3] + " " + VariableDocument.GetInstance.equiped[4] + " " + VariableDocument.GetInstance.equiped[5]);
        //装备前更新角色属性值为未装备时的值
        //Debug.Log(VariableDocument.GetInstance.role_attribute[0]);
        //Debug.Log(VariableDocument.GetInstance.per_role_attribute[0]);
        for(int e = 0;e < 5; e++)
        {
            VariableDocument.GetInstance.role_attribute[e] = VariableDocument.GetInstance.per_role_attribute[e];
        }
        //更改人物的属性
        for (int e = 0; e < 6; e++)
        {
            if (VariableDocument.GetInstance.equiped[e] != -1)//证明有装备
            {
                for (int c = 0; c < 5; c++)
                {
                    VariableDocument.GetInstance.role_attribute[c] += mainItem.itemList[VariableDocument.GetInstance.equiped[e]].attribute[c];
                }
                parentObject[e].transform.GetChild(0).gameObject.SetActive(true);
            }
        }
    }


}
